﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors;
using MINERP.InfoConfig.Controller;
using MINERP.MODEL.InfoConfig;
using MINERP.DAL;
using MINERP.COM;
using MINERP.MODEL.FoundationModel;
using MINERP.DAL.CommonDAL;
namespace MINERP.InfoConfig
{
    public partial class FrmProductManager : FrmMDIChildFormTemplate
    {
        private int rowHandle =0;
        private ProductController                       _controller = null;
        private FlowTemplateController                  _flowTemplateController = null;
        private TechController                          _techController = null;
        private ProductEntity                           _productEntity = null;
        private static FrmProductManager instance = null;

        private FrmProductManager()
        {
            InitializeComponent();
        }
        public static FrmProductManager CreateInstance
        {
            get
            {
                if (instance == null)
                {
                    instance = new FrmProductManager();
                }
                return instance;
            }
        }
        private void FrmProductManager_Load(object sender, EventArgs e)
        {
            _controller = new ProductController();
            _flowTemplateController = new FlowTemplateController();
            _techController = new TechController();

            _techController.Grid = gridControlTech;
            _techController.View = gridViewTech;
            _techController.GetTechData();

            _flowTemplateController.Grid = gridControlFlowTemplate;
            _flowTemplateController.View = gridViewFlowTemplate;

            _controller.Grid = gridControlProduct;
            _controller.View = gridViewProduct;
            _controller.GetProductData();

            _controller.ComboBoxEdit = cmbPaperFace;
            _controller.LinkcmbPaperFace();

            _controller.ComboBoxEdit = cmbDefaultPrinter;
            _controller.LinkDefaultPrinter();

            _controller.ComboBoxEdit = cmbPaperType;
            _controller.LinkcmbPaperType();

            _controller.ComboBoxEdit = cmbPorductCategory;
            _controller.LinkcmbPorductCategory();

            _controller.ComboBoxEdit = cmbPorductType;
            _controller.LinkcmbPorductType();

            _controller.ComboBoxEdit = cmbCostType;
            _controller.LinkcmbCosType();
        }
        // 添加节点
        private void btnAddTech_Click(object sender, EventArgs e)
        {
            List<tb_Tech> list = _techController.GetCheckedTech();
            _flowTemplateController.AddTech(list);
        }

        //删除节点
        private void btnDeleteTech_Click(object sender, EventArgs e)
        {
            FlowTemplateEntity flowTemplateEntity = _flowTemplateController.GetFocusFlowTemplateObj();
            _flowTemplateController.DeleteFlowTemplate(flowTemplateEntity);
        }
        //下移节点
        private void btnDown_Click(object sender, EventArgs e)
        {
            _flowTemplateController.NextRecord();
        }
        //上移节点
        private void btnUp_Click(object sender, EventArgs e)
        {
            _flowTemplateController.PreRecord();
        }
                                                                      
        private void gridViewProduct_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            //tb_ProductType productType;
            //tb_CostType costType;
            
            rowHandle = e.FocusedRowHandle;
            //CostTypeController costTypeController = new CostTypeController();
            //ProductTypeController productTypeController = new ProductTypeController();
  
            _productEntity = (ProductEntity)gridViewProduct.GetRow(e.FocusedRowHandle);
            if (_productEntity != null)
            {
                OutProcessShop ops = _controller.GetProductDefaultOutShop(_productEntity.ProuctId);
                if (cmbHeightUnit.Text == "厘米")
                {
                    txtHeight.Text = (_productEntity.Height*2.54).ToString();
                }
                else
                {
                    txtHeight.Text = _productEntity.Height.ToString();
                }
                if (cmbWidthUnit.Text == "厘米")
                {
                    txtWidth.Text = (_productEntity.Width*2.54).ToString();
                }
                else
                {
                    txtWidth.Text = _productEntity.Width.ToString();
                }
                txtMnemonicCode.Text = _productEntity.MnemonicCode;
                txtPageNum.Text = _productEntity.PageNum.ToString();
                txtProductCode.Text = _productEntity.ProductCode;
                txtProductDes.Text = _productEntity.ProductDes;
                txtProductName.Text = _productEntity.ProductName;
                txtUnitPrice.Text = _productEntity.UnitPrice.ToString();
                txtAddPrice.Text = _productEntity.AppendPrice.ToString();
                
                cmbPaperFace.Text = _productEntity.PaperFaceName;
                cmbDefaultPrinter.Text = _productEntity.PrinterName;
                cmbPaperType.Text = _productEntity.PaperTypeName;
                cmbPorductCategory.Text = _productEntity.ProductCategoryName;
                cmbPorductType.Text = _productEntity.ProductTypeName;
                cmbCostType.Text = _productEntity.CostTypeName;
                lbDefaultOutShop.Text = ops == null ? "" : ops.OutShopName;
                textEditProductPrintName.Text = _controller.GetProductPrintName(_productEntity.ProuctId);
                if (cmbCHeightUnit.Text == "厘米")
                {
                    textEditCoverHeight.Text = (_productEntity.CoverHeigth*2.54).ToString();
                }
                else
                {
                    textEditCoverHeight.Text = _productEntity.CoverHeigth.ToString();
                }
                if (cmbCWidthUnit.Text == "厘米")
                {
                    textEditCoverWidth.Text = (_productEntity.CoverWidth*2.54).ToString();
                }
                else
                {
                    textEditCoverWidth.Text = _productEntity.CoverWidth.ToString();
                }
                checkEditIsRendered.Checked = _productEntity.IsRendered;
                checkEditIsComplex.Checked = _productEntity.IsComplex;
                chkIsPrintThumbnail.Checked = _productEntity.IsPrintThumbnail;
                _flowTemplateController.LinkFlowTemplateView(_productEntity.ProuctId);
            }

        }
        bool IsAddNew = false;
        OutProcessShop_Info CurrOutShop = new OutProcessShop_Info();
        private void btnAdd_Click(object sender, EventArgs e)
        {
         

            if (btnAdd.Text != "保存")
            {
                IsAddNew = true;
                _flowTemplateController.ClearList();
                PrepareAdd(true);
                txtProductName.Focus();
                return;
            }
            if (CheckData())
            {
                //Tb_Product tempproduct = _controller.GetProductObj(txtProductName.Text);
                //if (tempproduct != null)
                //{
                //    MessageBox.Show("该产品已存在！","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
                //    return;
                //}
                Cursor = Cursors.WaitCursor;
                ProductEntity product = new ProductEntity();
                product.ProductName = txtProductName.Text;
                product.AppendPrice = txtAddPrice.Text == string.Empty ? 0 : Convert.ToDouble(txtAddPrice.Text);
                product.UnitPrice =txtUnitPrice.Text==string.Empty?0: Convert.ToDouble(txtUnitPrice.Text);
                product.ProductCode = txtProductCode.Text;
                product.PageNum =Convert.ToInt32( txtPageNum.Text.Trim());
                product.ProductDes = txtProductDes.Text;
                if (cmbWidthUnit.Text == "厘米")
                {
                    product.Width =Math.Round( Convert.ToDouble(txtWidth.Text.Trim())/2.54,2,MidpointRounding.AwayFromZero);
                }
                else
                {
                    product.Width = Convert.ToDouble(txtWidth.Text.Trim());
                }
                if (cmbHeightUnit.Text == "厘米")
                {
                    product.Height =Math.Round(Convert.ToDouble(txtHeight.Text.Trim())/2.54,2,MidpointRounding.AwayFromZero);
                }
                else
                {
                    product.Height = Convert.ToDouble(txtHeight.Text.Trim());
                }
                
                product.PaperFaceName = cmbPaperFace.Text;
                product.PaperTypeName = cmbPaperType.Text;
                product.PrinterName = cmbDefaultPrinter.Text;
                product.ProductCategoryName = cmbPorductCategory.Text;
                product.ProductTypeName = cmbPorductType.Text;
                product.CostTypeName = cmbCostType.Text;
                product.MnemonicCode = txtMnemonicCode.Text;
                product.PrinterName = textEditProductPrintName.Text.Trim();
                //textEditCoverHeight.Text = _productEntity.CoverHeigth.ToString();
                //textEditCoverWidth.Text = _productEntity.CoverWidth.ToString();
                //checkEditIsRendered.Checked = _productEntity.IsRendered;
                if (cmbCWidthUnit.Text == "厘米")
                {
                    product.CoverWidth = Math.Round(Convert.ToDouble(textEditCoverWidth.Text) / 2.54, 2, MidpointRounding.AwayFromZero);
                }
                else
                {
                    product.CoverWidth = Convert.ToDouble(textEditCoverWidth.Text);
                }
                if (cmbCHeightUnit.Text =="厘米")
                {
                    product.CoverHeigth =Math.Round( Convert.ToDouble(textEditCoverHeight.Text)/2.54,2,MidpointRounding.AwayFromZero);
                }
                else
                {
                    product.CoverHeigth = Convert.ToDouble(textEditCoverHeight.Text);
                }
                product.IsRendered = checkEditIsRendered.Checked;
                product.IsComplex = checkEditIsComplex.Checked;
                product.IsPrintThumbnail = chkIsPrintThumbnail.Checked;
                _controller.AddProduct(product, _flowTemplateController,CurrOutShop.OutShopId);


                //link datagrid
                _controller.Grid = gridControlProduct;
                _controller.View = gridViewProduct;
                _controller.GetProductData();
                if (_controller.View.RowCount > 1)
                {
                    _controller.View.FocusedRowHandle = _controller.View.RowCount - 1;
                }

                PrepareAdd(false);
                Cursor = Cursors.Default;
                MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                IsAddNew = false;
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (btnUpdate.Text != "保存")
            {
                PrepareUpdate(true);
                txtProductName.Focus();
                return;
            }
            if (CheckData())
            {
                Cursor = Cursors.WaitCursor;
                _productEntity.ProductName = txtProductName.Text;
                _productEntity.AppendPrice = txtAddPrice.Text == string.Empty ? 0 : Convert.ToDouble(txtAddPrice.Text);
                _productEntity.UnitPrice = txtUnitPrice.Text == string.Empty ? 0 : Convert.ToDouble(txtUnitPrice.Text);
                _productEntity.ProductCode = txtProductCode.Text;
                _productEntity.PageNum = Convert.ToInt32(txtPageNum.Text.Trim());
                _productEntity.ProductDes = txtProductDes.Text;
                //_productEntity.Width = Convert.ToDouble(txtWidth.Text.Trim());
                //_productEntity.Height = Convert.ToDouble(txtHeight.Text.Trim());
                if (cmbWidthUnit.Text == "厘米")
                {
                    _productEntity.Width = Math.Round(Convert.ToDouble(txtWidth.Text.Trim()) / 2.54, 2, MidpointRounding.AwayFromZero);
                }
                else
                {
                    _productEntity.Width = Convert.ToDouble(txtWidth.Text.Trim());
                }
                if (cmbHeightUnit.Text == "厘米")
                {
                    _productEntity.Height = Math.Round(Convert.ToDouble(txtHeight.Text.Trim()) / 2.54, 2, MidpointRounding.AwayFromZero);
                }
                else
                {
                    _productEntity.Height = Convert.ToDouble(txtHeight.Text.Trim());
                }
                _productEntity.PaperFaceName = cmbPaperFace.Text;
                _productEntity.PaperTypeName = cmbPaperType.Text;
                _productEntity.PrinterName = cmbDefaultPrinter.Text;
                _productEntity.ProductCategoryName = cmbPorductCategory.Text;
                _productEntity.ProductTypeName = cmbPorductType.Text;
                _productEntity.CostTypeName = cmbCostType.Text;
                _productEntity.MnemonicCode = txtMnemonicCode.Text;
                _productEntity.PrintName = textEditProductPrintName.Text.Trim();
                //_productEntity.CoverWidth = Convert.ToDouble(textEditCoverWidth.Text);
                //_productEntity.CoverHeigth = Convert.ToDouble(textEditCoverHeight.Text);
                if (cmbCWidthUnit.Text == "厘米")
                {
                    _productEntity.CoverWidth = Math.Round(Convert.ToDouble(textEditCoverWidth.Text) / 2.54, 2, MidpointRounding.AwayFromZero);
                }
                else
                {
                    _productEntity.CoverWidth = Convert.ToDouble(textEditCoverWidth.Text);
                }
                if (cmbCHeightUnit.Text == "厘米")
                {
                    _productEntity.CoverHeigth = Math.Round(Convert.ToDouble(textEditCoverHeight.Text) /2.54, 2, MidpointRounding.AwayFromZero);
                }
                else
                {
                    _productEntity.CoverHeigth = Convert.ToDouble(textEditCoverHeight.Text);
                }
                _productEntity.IsRendered = checkEditIsRendered.Checked;
                _productEntity.IsComplex = checkEditIsComplex.Checked;
                _productEntity.IsPrintThumbnail = chkIsPrintThumbnail.Checked;
                _controller.UpdateProduct(_productEntity, _flowTemplateController);

                //link datagrid
                _controller.Grid = gridControlProduct;
                _controller.View = gridViewProduct;
                _controller.GetProductData(rowHandle);

                PrepareUpdate(false);
                Cursor = Cursors.Default;
                MessageBox.Show("更新成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK == MessageBox.Show("确认删除吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
            {

                _controller.DeleteProduct(_productEntity);

                //link datagrid
                _controller.Grid = gridControlProduct;
                _controller.View = gridViewProduct;
                _controller.GetProductData();
            }
        }

        // Cancel button
        private void btnCancel_Click(object sender, EventArgs e)
        {
            txtUnitPrice.Text = string.Empty;
            txtUnitPrice.Enabled = false;
            txtAddPrice.Text = string.Empty;
            txtAddPrice.Enabled = false;
            txtProductName.Enabled = false;
            txtUnitPrice.Enabled = false;
            txtAddPrice.Enabled = false;
            txtProductCode.Enabled = false;
            txtPageNum.Enabled = false;
            txtProductDes.Enabled = false;
            txtWidth.Enabled = false;
            txtHeight.Enabled = false;
            cmbPaperFace.Enabled = false;
            cmbPaperType.Enabled = false;
            cmbDefaultPrinter.Enabled = false;
            cmbPorductCategory.Enabled = false;
            cmbPorductType.Enabled = false;
            cmbCostType.Enabled = false;
            textEditCoverHeight.Enabled = false;
            textEditCoverWidth.Enabled = false;
            checkEditIsRendered.Enabled = false;
            checkEditIsComplex.Enabled = false;
            chkIsPrintThumbnail.Enabled = false;


            btnAddTech.Enabled = false;
            btnDeleteTech.Enabled = false;
            btnUp.Enabled = false;
            btnDown.Enabled = false;


            btnAdd.Text = "添加";
            btnUpdate.Text = "更新";
            btnAddPrice.Text = "加价";
            btnReducePrice.Text = "减价";
            btnAdd.Enabled = true;
            btnUpdate.Enabled = true;
            btnDelete.Enabled = true;
            btnAddPrice.Enabled = true;
            btnReducePrice.Enabled = true;

        }

        /// <summary>
        /// 检查数据完整性

        /// </summary>
        /// <returns></returns>
        private bool CheckData()
        {
            bool flag = true;
            if (txtProductName.Text == string.Empty)
            {
                txtProductName.Focus();
                MessageBox.Show("产品名称不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (txtProductCode.Text == string.Empty)
            {
                txtProductCode.Focus();
                MessageBox.Show("产品号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }

            if (txtPageNum.Text == string.Empty)
            {
                txtPageNum.Focus();
                MessageBox.Show("页数不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }

            if (txtProductDes.Text == string.Empty)
            {
                txtProductDes.Focus();
                MessageBox.Show("产品描述不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (txtWidth.Text == string.Empty)
            {
                txtWidth.Focus();
                MessageBox.Show("宽度不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (txtHeight.Text == string.Empty)
            {
                txtHeight.Focus();
                MessageBox.Show("高度不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (cmbPaperFace.Text == string.Empty)
            {
                cmbPaperFace.Focus();
                MessageBox.Show("纸面不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (cmbPaperType.Text == string.Empty)
            {
                cmbPaperType.Focus();
                MessageBox.Show("纸型不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (cmbPorductCategory.Text == string.Empty)
            {
                cmbPorductCategory.Focus();
                MessageBox.Show("产品分类不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (cmbPorductType.Text == string.Empty)
            {
                cmbPorductType.Focus();
                MessageBox.Show("产品类型不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            if (cmbCostType.Text== string.Empty)
            {
                cmbCostType.Focus();
                MessageBox.Show("计价类型不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            return flag;
        }
        /// <summary>
        /// 添加前控件设置

        /// </summary>
        /// <param name="bl"></param>
        private void PrepareAdd(bool bl)
        {
            txtProductName.Enabled = bl;
            txtAddPrice.Enabled = bl;
            txtUnitPrice.Enabled = bl;
            txtProductCode.Enabled = bl;
            txtPageNum.Enabled = bl;
            txtProductDes.Enabled = bl;
            txtWidth.Enabled = bl;
            txtHeight.Enabled = bl;
            cmbPaperFace.Enabled = bl;
            cmbPaperType.Enabled = bl;
            cmbDefaultPrinter.Enabled = bl;
            cmbPorductCategory.Enabled = bl;
            cmbPorductType.Enabled = bl;
            cmbCostType.Enabled = bl;
           
            btnAddTech.Enabled = bl;
            btnDeleteTech.Enabled = bl;
            btnUp.Enabled = bl;
            btnDown.Enabled = bl;
            textEditCoverHeight.Enabled = bl;
            textEditCoverWidth.Enabled = bl;
            checkEditIsRendered.Enabled = bl;
            checkEditIsComplex.Checked = bl;
            chkIsPrintThumbnail.Checked = bl;

            txtProductName.Text = string.Empty;
            txtUnitPrice.Text = string.Empty;
            txtAddPrice.Text = string.Empty;
            txtProductCode.Text = string.Empty;
            txtPageNum.Text = string.Empty;
            txtProductDes.Text = string.Empty;
            txtWidth.Text = string.Empty;
            txtHeight.Text = string.Empty;
            cmbPaperFace.SelectedIndex = -1;
            cmbPaperType.SelectedIndex = -1;
            cmbDefaultPrinter.SelectedIndex = -1;
            cmbPorductCategory.SelectedIndex = -1;
            textEditProductPrintName.Enabled = bl;


            if (bl)
            {

                btnAdd.Text = "保存";
                btnUpdate.Enabled = false;
                btnDelete.Enabled = false;
                btnReducePrice.Enabled = false;
                btnAddPrice.Enabled = false;
            }
            else
            {
                btnAdd.Text = "添加";
                btnUpdate.Enabled = true;
                btnDelete.Enabled = true;
                btnReducePrice.Enabled = true;
                btnAddPrice.Enabled = true;
            }
        }

        /// <summary>
        /// 更新前控件设置

        /// </summary>
        /// <param name="bl"></param>
        private void PrepareUpdate(bool bl)
        {

            txtProductName.Enabled = bl;
            txtAddPrice.Enabled = bl;
            txtUnitPrice.Enabled = bl;
            txtProductCode.Enabled = bl;
            txtPageNum.Enabled = bl;
            txtProductDes.Enabled = bl;
            txtWidth.Enabled = bl;
            txtHeight.Enabled = bl;
            cmbPaperFace.Enabled = bl;
            cmbPaperType.Enabled = bl;
            cmbDefaultPrinter.Enabled = bl;
            cmbPorductCategory.Enabled = bl;
            cmbPorductType.Enabled = bl;
            cmbCostType.Enabled = bl;

            textEditCoverHeight.Enabled = bl;
            textEditCoverWidth.Enabled = bl;
            checkEditIsRendered.Enabled = bl;
            checkEditIsComplex.Enabled = bl;
            chkIsPrintThumbnail.Enabled = bl;
            btnAddTech.Enabled = bl;
            btnDeleteTech.Enabled = bl;
            btnUp.Enabled = bl;
            btnDown.Enabled = bl;
            textEditProductPrintName.Enabled = bl;

            if (bl)
            {

                btnUpdate.Text = "保存";
                btnAdd.Enabled = false;
                btnDelete.Enabled = false;
                btnReducePrice.Enabled =false;
                btnAddPrice.Enabled = false;
            }
            else
            {
                btnUpdate.Text = "更新";
                btnAdd.Enabled = true;
                btnDelete.Enabled = true;
                btnReducePrice.Enabled = true;
                btnAddPrice.Enabled = true;
            }
        }
        private void FrmProductManager_FormClosed(object sender, FormClosedEventArgs e)
        {
            instance = null;
        }

        private void txtPageNum_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                Convert.ToInt32(txtPageNum.Text.Trim());
            }
            catch
            {
                MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtPageNum.Text = string.Empty;
            }
        }

        private void txtWidth_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                Convert.ToDouble(txtWidth.Text.Trim());
            }
            catch
            {
                MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtWidth.Text = string.Empty;
            }
        }

        private void txtHeight_KeyUp(object sender, KeyEventArgs e)
        {
            try
            {
                Convert.ToDouble(txtHeight.Text.Trim());
            }
            catch
            {
                MessageBox.Show("请输入数字", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtHeight.Text = string.Empty;
            }
        }

        private void txtProductName_KeyUp(object sender, KeyEventArgs e)
        {
            if (txtProductName.Text.Contains('/') || txtProductName.Text.Contains('\\') || txtProductName.Text.Contains('|') || txtProductName.Text.Contains(':') || txtProductName.Text.Contains('?') || txtProductName.Text.Contains('*') || txtProductName.Text.Contains('\"') || txtProductName.Text.Contains('<') || txtProductName.Text.Contains('>'))
            {
                MessageBox.Show("不能含有下列任何符号之一 / \\ * | ？ \" : < >", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtProductName.Text = string.Empty;
            }
        }

        private void groupControl1_Paint(object sender, PaintEventArgs e)
        {
           
        }

        private void txtProductName_Leave(object sender, EventArgs e)
        {
            txtMnemonicCode.Text = IsChina(txtProductName.Text);
        }

        //private void txtProductName_TextChanged(object sender, EventArgs e)
        //{

        //    //txtMnemonicCode.Text = MnemonicCode.chinesecap(txtProductName.Text);
        //}

        private  string IsChina(string CString)
        {
            StringBuilder  temp = new StringBuilder();
            char[] charTem = CString.ToCharArray(); 
            foreach (char ch in charTem)
            {
                if (Convert.ToInt32(ch) < Convert.ToInt32(Convert.ToChar(128)))
                {
                    temp.Append(ch);
                }
                else
                {
                    temp.Append(MnemonicCode.chinesecap(ch.ToString()));
                }
            }
            return temp.ToString().ToUpper();
        }

        private void btnAddPrice_Click(object sender, EventArgs e)
        {
            FrmChangePrice frmChangePrice = new FrmChangePrice();
            frmChangePrice.IsAddPrice = true;
            frmChangePrice.ChangePriceName = ((SimpleButton)sender).Text;
            frmChangePrice.product = _productEntity;
            frmChangePrice.ShowDialog();
            //if (btnAddPrice.Text == "加价")
            //{
            //    btnAddPrice.Text = "保存";

            //    txtAddPrice.Text = string.Empty;
            //    txtUnitPrice.Text = string.Empty;
            //    txtAddPrice.Enabled = true;
            //    txtUnitPrice.Enabled = true;


            //    btnAdd.Enabled = false;
            //    btnUpdate.Enabled = false;
            //    btnDelete.Enabled = false;
            //    btnReducePrice.Enabled = false;
            //}
            //else
            //{
            //    if (txtUnitPrice.Text == string.Empty)
            //    {
            //        MessageBox.Show("请输入单价的加价金额", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        txtUnitPrice.Focus();
            //        return;
            //    }
            //    if (txtAddPrice.Text == string.Empty)
            //    {
            //        MessageBox.Show("请输入加页价的加价金额", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        txtAddPrice.Focus();
            //        return;
            //    }
            //    _controller.AddPrice(_productEntity,Convert.ToDouble( txtAddPrice.Text), Convert.ToDouble(txtUnitPrice.Text));
            _controller.Grid = gridControlProduct;
            _controller.View = gridViewProduct;
            _controller.GetProductData(rowHandle);

            //    txtAddPrice.Text = string.Empty;
            //    txtUnitPrice.Text = string.Empty;
            //    txtAddPrice.Enabled = false;
            //    txtUnitPrice.Enabled = false;

            //    btnAdd.Enabled = true;
            //    btnUpdate.Enabled = true;
            //    btnDelete.Enabled = true;
            //    btnReducePrice.Enabled = true;
            //    btnAddPrice.Text = "加价";
            //MessageBox.Show("加价成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //}
        }

        private void btnReducePrice_Click(object sender, EventArgs e)
        {
             FrmChangePrice frmChangePrice = new FrmChangePrice();
            frmChangePrice.IsAddPrice = false;
            frmChangePrice.ChangePriceName = ((SimpleButton)sender).Text;
            frmChangePrice.product = _productEntity;
            frmChangePrice.ShowDialog();
            //if (btnReducePrice.Text == "减价")
            //{
            //    btnReducePrice.Text = "保存";

            //    txtAddPrice.Text = string.Empty;
            //    txtUnitPrice.Text = string.Empty;
            //    txtAddPrice.Enabled = true;
            //    txtUnitPrice.Enabled = true;

            //    btnAdd.Enabled = false;
            //    btnUpdate.Enabled = false;
            //    btnDelete.Enabled = false;
            //    btnAddPrice.Enabled = false;
            //}
            //else
            //{
            //    if (txtUnitPrice.Text==string.Empty)
            //    {
            //        MessageBox.Show("请输入单价的减价金额", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        txtUnitPrice.Focus();
            //        return;
            //    }
            //    if (txtAddPrice.Text==string.Empty)
            //    {
            //        MessageBox.Show("请输入加页价的减价金额", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        txtAddPrice.Focus();
            //        return;
            //    }

            //    _controller.ReducePrice(_productEntity, Convert.ToDouble(txtAddPrice.Text), Convert.ToDouble(txtUnitPrice.Text));
                _controller.Grid = gridControlProduct;
                _controller.View = gridViewProduct;
                _controller.GetProductData(rowHandle);


            //    txtAddPrice.Text = string.Empty;
            //    txtUnitPrice.Text = string.Empty;
            //    txtAddPrice.Enabled = false;
            //    txtUnitPrice.Enabled = false;

            //    btnAdd.Enabled = true;
            //    btnUpdate.Enabled = true;
            //    btnDelete.Enabled = true;
            //    btnAddPrice.Enabled = true;
            //    btnReducePrice.Text = "减价";
                //MessageBox.Show("减价成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
    

            //}
        }

        private void groupControl1_Paint_1(object sender, PaintEventArgs e)
        {

        }

        private void lkProductDefaultShop_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (!IsAddNew)
            {
                ProductEntity productEntity = (ProductEntity)gridViewProduct.GetFocusedRow();
                FrmProductOutShopManager frmProductOutShopManager = new FrmProductOutShopManager(productEntity.ProuctId);
                frmProductOutShopManager.ShowDialog();
            }
            else
            {
                FrmNewProductOutShop frmNew = new FrmNewProductOutShop();
                frmNew.SendOutShop+=new FrmNewProductOutShop.SendMessage(ShowSendOutShop);
                frmNew.ShowDialog();
            }
        }

        void ShowSendOutShop(OutProcessShop_Info  outshop)
        {
            lbDefaultOutShop.Text = outshop.OutShopName;
            CurrOutShop = outshop;
 
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            FrmPhotoSize frm = new FrmPhotoSize(_productEntity.ProuctId);
            frm.ShowDialog();
        }

    }
}
